package com.zzx.controller;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zzx.SbootPropertiesUtil;

/**
 * 测试项目配置
 * @author zzx
 *
 */
@RestController
public class TestController {
	
	@Autowired
	private SbootPropertiesUtil sp ;
	
	//@Value("${user}")
	//private String user;
	@RequestMapping(value="/test",method=RequestMethod.GET)
	public Map<String,String> testSayHello() throws IOException{
		System.err.println("*******进入后台开始***********");
		Map<String,String> map = new HashMap<String,String>();
		InputStream in = new BufferedInputStream(new FileInputStream("src/main/resources/text.properties"));
		
		StringBuffer   out   =   new   StringBuffer(); 
        byte[]   b   =   new   byte[4096]; 
        for   (int   n;   (n   =   in.read(b))   !=   -1;)   { 
                out.append(new   String(b,   0,   n)); 
        } 
        String str = out.toString(); 
        in.close();
		System.out.println("文件读取的： "+ str);
		
		map.put("userName", "张晓明");
		map.put("userSex", "女");
		map.put("content", str);
		System.err.println("*******进入后台 结束***********");
		return map;
	}
	@RequestMapping(value="/getFile",method=RequestMethod.GET)
	public void getFile() {
		System.err.println("*******进入后台 结束***********");
		
		//System.err.println("**"+sp.toString());
		Map<String,String> map = sp.getMap();
		Iterator iter = map.entrySet().iterator();
		while(iter.hasNext()){
			Map.Entry entry = (Map.Entry)iter.next();
	        Object key = entry.getKey();
	        Object val = entry.getValue();
	        System.err.println(key+ " **** "+val);
		}
		System.err.println("**FTP_HOST_IP*"+map.get("FTP_HOST_IP"));
	}
	
}
